home *** CD-ROM | disk | FTP | other *** search
/ Champak 66 / Vol 66.iso / games / bluep.swf / scripts / __Packages / Music.as < prev    next >
Encoding:
Text File  |  2013-04-24  |  2.8 KB  |  112 lines

  1. class Music
  2. {
  3.    var mySound;
  4.    var volume;
  5.    var currentTrack;
  6.    var inCrossfade;
  7.    var state;
  8.    var changeSongs;
  9.    var maxVolume;
  10.    var targetVolume;
  11.    var volumeSpeed;
  12.    function Music()
  13.    {
  14.       this.mySound = new Sound();
  15.       this.volume = 100;
  16.       this.currentTrack = "";
  17.       this.inCrossfade = false;
  18.       this.state = false;
  19.       this.changeSongs = true;
  20.       this.maxVolume = 60;
  21.    }
  22.    function SetMaxVolume(vol)
  23.    {
  24.       this.maxVolume = vol;
  25.    }
  26.    function SetTrack(setMusic)
  27.    {
  28.       trace(setMusic);
  29.       if(setMusic == this.currentTrack)
  30.       {
  31.          this.changeSongs = false;
  32.       }
  33.       else
  34.       {
  35.          this.changeSongs = true;
  36.          this.currentTrack = setMusic;
  37.       }
  38.    }
  39.    function Play()
  40.    {
  41.       this.mySound.stop();
  42.       this.mySound.attachSound(this.currentTrack);
  43.       this.volume = this.maxVolume;
  44.       this.mySound.setVolume(this.volume);
  45.       this.mySound.start(0,2000);
  46.       this.state = true;
  47.    }
  48.    function Stop()
  49.    {
  50.       this.mySound.stop();
  51.       this.state = false;
  52.    }
  53.    function PlayWithCrossFade(secondDuration)
  54.    {
  55.       if(this.changeSongs == true)
  56.       {
  57.          if(this.state == true)
  58.          {
  59.             this.inCrossfade = true;
  60.             this.targetVolume = 0;
  61.             var _loc2_ = secondDuration * 30;
  62.             this.volumeSpeed = (this.targetVolume - this.volume) / (_loc2_ / 2);
  63.          }
  64.          else
  65.          {
  66.             this.mySound.stop();
  67.             this.mySound.attachSound(this.currentTrack);
  68.             this.mySound.start(0,2000);
  69.             this.state = true;
  70.             this.inCrossfade = false;
  71.             this.targetVolume = this.maxVolume;
  72.             this.volume = 0;
  73.             this.mySound.setVolume(0);
  74.             _loc2_ = secondDuration * 30;
  75.             this.volumeSpeed = (this.targetVolume - this.volume) / _loc2_;
  76.          }
  77.       }
  78.    }
  79.    function RunPlayer()
  80.    {
  81.       if(this.targetVolume != this.volume)
  82.       {
  83.          var _loc2_ = undefined;
  84.          _loc2_ = this.volume + this.volumeSpeed;
  85.          if(this.volumeSpeed < 0 && _loc2_ < 0)
  86.          {
  87.             _loc2_ = 0;
  88.          }
  89.          else if(this.volumeSpeed > 0 && _loc2_ > this.targetVolume)
  90.          {
  91.             _loc2_ = this.targetVolume;
  92.          }
  93.          this.volume = _loc2_;
  94.          this.mySound.setVolume(_loc2_);
  95.       }
  96.       if(this.inCrossfade == true)
  97.       {
  98.          if(this.volume <= 0)
  99.          {
  100.             this.volumeSpeed *= -1;
  101.             this.inCrossfade = false;
  102.             this.targetVolume = this.maxVolume;
  103.             this.mySound.stop();
  104.             this.mySound.attachSound(this.currentTrack);
  105.             this.mySound.setVolume(0);
  106.             this.mySound.start(0,2000);
  107.             this.state = true;
  108.          }
  109.       }
  110.    }
  111. }
  112.